﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using _4T.BLL;
using _4T.Data;
using System.Web.UI.HtmlControls;
using System.Globalization;

namespace _4T
{
    public partial class Index : System.Web.UI.Page
    {
        private const string PREFIX_NAME = "<span style='text-transform: none; text-decoration: underline;'>Người đại diện:</span><br />";
        private const string PREFIX_TIME = "<span style='text-transform: none; text-decoration: underline;'>Vào lúc:</span><br />";
        private const string PREFIX_PROFILENAME = "<span style='text-transform: none; text-decoration: underline;'>Tên bệnh nhân:</span><br />";
        private const string PREFIX_PROFILEID = "<span style='text-transform: none; text-decoration: underline;'>Mã hồ sơ:</span><br />";
        private const string PREFIX_DESCRIPTION = "<span style='text-transform: none; text-decoration: underline;'>Mô tả:</span><br />";
        private const string VERIFING_RESULT = "<span style='text-transform: none; text-decoration: underline;'>Kết quả xác minh:</span><br />";
        private const string MONEY = "<span style='text-transform: none; text-decoration: underline;'>Số tiền:</span><br />";
        private const string CURENCY = " VND";
        private const string PROFILE_STOP_COLOR = "red";
        private const string PROCESSED_STATUS = "<span style='text-transform: none; text-decoration: underline;'>Trạng thái:</span><br />";
        private const int MAX_DESCRIPTION = 120;
        private const int THUMBNAILSIZE = 64;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PQTPager1.CurrentPageIndex = 0;
                BindData();
            }
        }

        private void BindData()
        {
            List<ProfileInfoStatusDetail> list = new List<ProfileInfoStatusDetail>();

            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                list = new ProfileBLL().GetListProfilePaging(0, 1, "", -1).Where(n => n.ProfileCode.Equals(Request.QueryString["id"])).ToList();
                PQTPager1.RecordCount = 1;
            }
            else
            {
                int bynRecycle = 0;

                list = new ProfileBLL().GetListProfilePaging(PQTPager1.CurrentPageIndex + 1, PQTPager1.PageSize, "", bynRecycle);
                ProfileInfoBLL profileInfoBLL = new ProfileInfoBLL();
                int total = profileInfoBLL.GetTotalNumberProfile(bynRecycle);
                if (total > 0)
                {
                    PQTPager1.RecordCount = total;
                }
            }

            rptProfileList.DataSource = list;
            rptProfileList.DataBind();

        }
        protected void PQTPager1_PageIndexChanged(object sender, PQT.PageIndexChangedEventArgs e)
        {
            PQTPager1.CurrentPageIndex = e.NewPageIndex;
            BindData();
        }

        protected void rptProfileList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            ((Label)(e.Item.FindControl("lblPrefixProfileName"))).Text = PREFIX_PROFILENAME;
            ((Label)(e.Item.FindControl("lblPrefixProfileID"))).Text = PREFIX_PROFILEID;

            ProfileInfoStatusDetail item = (ProfileInfoStatusDetail)e.Item.DataItem;
            string status = "<span style='font-weight:bold'>Đang xử lý</span>";
            if (item.Stage == 6)
            {
                status = "<span style='font-weight:bold'>Hoàn thành</span>";
            }
            else
            {
                if (item.Status == 2)
                    status = "<span style='font-weight:bold'>Đã hủy</span>";
            }
            ((Label)(e.Item.FindControl("lblPrefixProfileStatus"))).Text = PROCESSED_STATUS + status;


            PatientInfo patientInfo = new DAL.PatientInfoDAL().GetPatientInfo2(item.ProfileCode);
            MedicalInfo medicalInfo = new DAL.MedicalInfoDAL().GetMedicalInfo2(item.ProfileCode);

            BindDataForProfileDetail(item.ProfileCode, patientInfo, medicalInfo, e);
            if (item != null && item.ListUrl != null && item.ListUrl.Count > 0)
            {
                switch (item.Stage)
                {
                    case 2:
                        {
                            BindDataForStage1(item, e);
                            if (item.Status != 0)
                                BindDataForStage2(item, e);

                            ShowCommentStage2(item, e);
                        }
                        break;
                    case 3:
                        {
                            BindDataForStage1(item, e);
                            BindDataForStage2(item, e);
                            if (item.Status != 0)
                                BindDataForStage3(item, e);

                            ShowCommentStage2(item, e);
                            ShowCommentStage3(item, e);
                        } break;
                    case 4:
                        {
                            BindDataForStage1(item, e);
                            BindDataForStage2(item, e);
                            BindDataForStage3(item, e);
                            if (item.Status != 0)
                                BindDataForStage4(item, e);

                            ShowCommentStage2(item, e);
                            ShowCommentStage3(item, e);
                            ShowCommentStage4(item, e);
                        } break;
                    case 5:
                        {
                            BindDataForStage1(item, e);
                            BindDataForStage2(item, e);
                            BindDataForStage3(item, e);
                            BindDataForStage4(item, e);
                            if (item.Status != 0)
                                BindDataForStage5(item, e);

                            ShowCommentStage2(item, e);
                            ShowCommentStage3(item, e);
                            ShowCommentStage4(item, e);
                        } break;
                    case 6:
                        {
                            BindDataForStage1(item, e);
                            BindDataForStage2(item, e);
                            BindDataForStage3(item, e);
                            BindDataForStage4(item, e);
                            BindDataForStage5(item, e);

                            ShowCommentStage2(item, e);
                            ShowCommentStage3(item, e);
                            ShowCommentStage4(item, e);
                        } break;
                }
            }
        }



        private void ShowCommentStage2(ProfileInfoStatusDetail item, RepeaterItemEventArgs e)
        {


            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Repeater rptCommentFilter = (Repeater)e.Item.FindControl("rptCommentFilter");
                if (rptCommentFilter != null)
                {
                    var result = new DAL.CommentDAL().GetListComment(item.ProfileCode, 2).ToList();
                    rptCommentFilter.DataSource = result;
                    rptCommentFilter.DataBind();
                    if (item.Stage >= 2 && result.Count > 0)
                        ((HtmlControl)e.Item.FindControl("FrameCommentFilter")).Style["display"] = "block";
                }
            }
        }

        private void ShowCommentStage3(ProfileInfoStatusDetail item, RepeaterItemEventArgs e)
        {


            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Repeater rptCommentVerifier = (Repeater)e.Item.FindControl("rptCommentVerifier");
                if (rptCommentVerifier != null)
                {
                    var result = new DAL.CommentDAL().GetListComment(item.ProfileCode, 3).ToList();
                    rptCommentVerifier.DataSource = result;
                    rptCommentVerifier.DataBind();
                    if (item.Stage >= 3 && result.Count > 0)
                        ((HtmlControl)e.Item.FindControl("FrameCommentVerifier")).Style["display"] = "block";
                }
            }
        }

        private void ShowCommentStage4(ProfileInfoStatusDetail item, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Repeater rptCommentApprove = (Repeater)e.Item.FindControl("rptCommentApprove");
                if (rptCommentApprove != null)
                {
                    var result = new DAL.CommentDAL().GetListComment(item.ProfileCode, 4).ToList();
                    rptCommentApprove.DataSource = result;
                    rptCommentApprove.DataBind();
                    if (item.Stage >= 4 && result.Count > 0)
                        ((HtmlControl)e.Item.FindControl("FrameCommentApprove")).Style["display"] = "block";
                }
            }
        }

        private void BindDataForStage1(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            if (pf.Status == 2 && pf.Stage == 1)
            {
                //
            }
            ProfileStageLink link1 = pf.ListUrl.Where(l => l.Stage.Equals(1)).SingleOrDefault();
            InfoSupplierInfo infoSupplierInfo = new DAL.InfoSupplierInfoDAL().GetInfoSupplierInfo2(pf.ProfileCode);
            if (!string.IsNullOrEmpty(infoSupplierInfo.SupplierName))
                ((Label)(e.Item.FindControl("lblPrefixNameProposer"))).Text = PREFIX_NAME + "<span style='font-weight:bold'>" + infoSupplierInfo.SupplierName + "</span>";
            if (link1 != null)
            {
                if (link1.Description != null && link1.Description.Length > 0)
                {
                    ((Label)e.Item.FindControl("lblDescriptionProposer")).Text = PREFIX_DESCRIPTION + (link1.Description.Length > MAX_DESCRIPTION ? link1.Description.Substring(0, MAX_DESCRIPTION) : link1.Description);
                }
                if (link1.EditTime != null)
                {

                    ((Label)e.Item.FindControl("lbProposeTime")).Text = PREFIX_TIME + link1.EditTime;
                }
                BindDetailForPropose(pf.ProfileCode, link1, e);
            }
        }

        private void BindDataForStage2(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            if (pf.Status == 2 && pf.Stage == 2)
            {
                ((HtmlControl)e.Item.FindControl("frameContentFilter")).Style["background-color"] = PROFILE_STOP_COLOR;
            }
            ProfileStageLink link2 = pf.ListUrl.Where(l => l.Stage.Equals(2)).SingleOrDefault();
            ((Label)(e.Item.FindControl("lblPrefixNameFilter"))).Text = PREFIX_NAME + "<span style='font-weight:bold'>" + pf.Filter + "</span>"; ;
            if (link2 != null)
            {
                if (link2.Description != null && link2.Description.Length > 0)
                    ((Label)e.Item.FindControl("lblDescriptionFilter")).Text = PREFIX_DESCRIPTION + (link2.Description.Length > MAX_DESCRIPTION ? link2.Description.Substring(0, MAX_DESCRIPTION) : link2.Description);
                if (link2.EditTime != null)
                    ((Label)e.Item.FindControl("lbFilterTime")).Text = PREFIX_TIME + link2.EditTime;
                BindDetailForFilter(pf.ProfileCode, link2, e);
            }
        }

        private void BindDataForStage3(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            string result = "Trình duyệt";
            if (pf.Status == 2 && pf.Stage == 3)
            {
                ((HtmlControl)e.Item.FindControl("frameContentVerifier")).Style["background-color"] = PROFILE_STOP_COLOR;
                result = "Không trình duyệt";
            }

            ((Label)e.Item.FindControl("lblVerifingResult")).Text = VERIFING_RESULT + result;
            ProfileStageLink link3 = pf.ListUrl.Where(l => l.Stage.Equals(3)).FirstOrDefault();
            //Data.IDataContext.CMSConsiderAndDecide stage3Info = new ConsiderAndDecideBLL().GetConsiderAndDecideByProfile(pf.ProfileCode);

            ((Label)(e.Item.FindControl("lblPrefixNameVerifier"))).Text = PREFIX_NAME + "<span style='font-weight:bold'>" + pf.Verifier + "</span>"; ;
            if (link3 != null)
            {
                if (link3.Description != null && link3.Description.Length > 0)
                    ((Label)e.Item.FindControl("lblDescriptionVerifier")).Text = PREFIX_DESCRIPTION + (link3.Description.Length > MAX_DESCRIPTION ? link3.Description.Substring(0, MAX_DESCRIPTION) : link3.Description);
                if (link3.EditTime != null)
                    ((Label)e.Item.FindControl("lbVerifyTime")).Text = PREFIX_TIME + link3.EditTime;
                BindDetailForVerify(pf.ProfileCode, link3, e);
            }
        }

        private void BindDataForStage4(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            if (pf.Stage == 4 && pf.Status == 2)
            {
                ((HtmlControl)e.Item.FindControl("frameContentApprover")).Style["background-color"] = PROFILE_STOP_COLOR;
            }
            string moneyValue = pf.Money;
            string moneyProcessed = moneyValue;
            for (int i = moneyValue.Length - 1; i >= 0; i = i - 3)
            {
                if (i == (moneyValue.Length - 1) && i > 2)
                {
                    i = i - 2;
                    moneyProcessed = moneyProcessed.Insert(i, ".");
                }
                else
                    if (i > 0)
                    {
                        moneyProcessed = moneyProcessed.Insert(i, ".");
                    }
            }
            ((Label)e.Item.FindControl("lblApproveMoney")).Text = MONEY + moneyProcessed + CURENCY;
            ProfileStageLink link4 = pf.ListUrl.Where(l => l.Stage.Equals(4)).SingleOrDefault();
            ((Label)(e.Item.FindControl("lblPrefixNameApprover"))).Text = PREFIX_NAME + "<span style='font-weight:bold'>" + pf.Approver + "</span>";
            if (link4 != null)
            {
                if (link4.EditTime != null)
                    ((Label)e.Item.FindControl("lbApproveTime")).Text = PREFIX_TIME + link4.EditTime;
                if (link4.Description != null && link4.Description.Length > 0)
                    ((Label)e.Item.FindControl("lblDescriptionApprover")).Text = PREFIX_DESCRIPTION + (link4.Description.Length > MAX_DESCRIPTION ? link4.Description.Substring(0, MAX_DESCRIPTION) : link4.Description);
                BindDetailForApprove(pf.ProfileCode, link4, e);
            }
        }

        private void BindDataForStage5(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            if (pf.Stage == 5 && pf.Status == 2)
            {
                ((HtmlControl)e.Item.FindControl("frameContentPayment")).Style["background-color"] = PROFILE_STOP_COLOR;
            }
            ProfileStageLink link5 = pf.ListUrl.Where(l => l.Stage.Equals(5)).SingleOrDefault();
            ((Label)(e.Item.FindControl("lbPaymentPerson"))).Text = PREFIX_NAME + "<span style='font-weight:bold'>" + pf.PaymentPerson + "</span>";
            if (link5 != null)
            {
                if (link5.Description != null && link5.Description.Length > 0)
                    ((Label)e.Item.FindControl("lblDescriptionPayment")).Text = PREFIX_DESCRIPTION + (link5.Description.Length > MAX_DESCRIPTION ? link5.Description.Substring(0, MAX_DESCRIPTION) : link5.Description);
                if (link5.EditTime != null)
                    ((Label)e.Item.FindControl("lbPaymentTime")).Text = PREFIX_TIME + link5.EditTime;
                BindDetailForPayment(pf.ProfileCode, link5, e);
            }
        }

        /*// Đề xuất
        private void BindDataForStageFilter(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            ProfileStageLink link1 = pf.ListUrl.Where(l => l.Stage.Equals(1)).SingleOrDefault();
            if (pf.Proposer.ToString().Equals("") == false)
            {
                ((Label)(e.Item.FindControl("lblPrefixNameProposer"))).Text = PREFIX_NAME;
            }
            if (link1 != null)
            {
                ((Label)e.Item.FindControl("lbProposeTime")).Text = PREFIX_TIME + link1.EditTime;
                if (link1.Description.Length > 0)
                {
                    ((Label)e.Item.FindControl("lblDescriptionProposer")).Text = PREFIX_DESCRIPTION + (link1.Description.Length > MAX_DESCRIPTION ? link1.Description.Substring(0, MAX_DESCRIPTION) : link1.Description);
                }
                BindDetailForPropose(pf.ProfileCode, link1, e);
            }

            if (pf.Status == 2)
            {
                ((HtmlControl)e.Item.FindControl("frameContentFilter")).Style["background-color"] = PROFILE_STOP_COLOR;
                ProfileStageLink link2 = pf.ListUrl.Where(l => l.Stage.Equals(2)).SingleOrDefault();
                if (pf.Filter.ToString().Equals("") == false)
                {
                    ((Label)(e.Item.FindControl("lblPrefixNameFilter"))).Text = PREFIX_NAME;
                }
                if (link2 != null)
                {
                    ((Label)e.Item.FindControl("lbFilterTime")).Text = PREFIX_TIME + link2.EditTime;
                    ((Label)e.Item.FindControl("lblDescriptionFilter")).Text = link2.Description.Length > MAX_DESCRIPTION ? link2.Description.Substring(0, MAX_DESCRIPTION) : link2.Description;
                    BindDetailForFilter(pf.ProfileCode, link2, e);
                }
            }
        }

        private void BindDataForStageVerifier(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            ProfileStageLink link1 = pf.ListUrl.Where(l => l.Stage.Equals(1)).FirstOrDefault();
            if (link1 != null)
            {
                if (pf.Proposer.ToString().Equals("") == false)
                {
                    ((Label)(e.Item.FindControl("lblPrefixNameProposer"))).Text = PREFIX_NAME;
                }
                ((Label)e.Item.FindControl("lbProposeTime")).Text = PREFIX_TIME + link1.EditTime;
                if (link1.Description.Length > 0)
                {
                    ((Label)e.Item.FindControl("lblDescriptionProposer")).Text = PREFIX_DESCRIPTION + (link1.Description.Length > MAX_DESCRIPTION ? link1.Description.Substring(0, MAX_DESCRIPTION) : link1.Description);
                }
                BindDetailForPropose(pf.ProfileCode, link1, e);
            }
            ProfileStageLink link2 = pf.ListUrl.Where(l => l.Stage.Equals(2)).FirstOrDefault();
            if (pf.Filter.ToString().Equals("") == false)
            {
                ((Label)(e.Item.FindControl("lblPrefixNameFilter"))).Text = PREFIX_NAME;
            }
            if (link2 != null)
            {
                ((Label)e.Item.FindControl("lbFilterTime")).Text = PREFIX_TIME + link2.EditTime;
                ((Label)e.Item.FindControl("lblDescriptionFilter")).Text = link2.Description.Length > MAX_DESCRIPTION ? link2.Description.Substring(0, MAX_DESCRIPTION) : link2.Description;
                BindDetailForFilter(pf.ProfileCode, link2, e);
            }
            //((HtmlControl)e.Item.FindControl("sVerify")).Style["color"] = "White";
            if (pf.Status == 0)
            {
                //((HtmlControl)e.Item.FindControl("sVerify")).Style["background-color"] = "Blue";
            }
            else
            {
                ((HtmlControl)e.Item.FindControl("frameContentVerifier")).Style["background-color"] = PROFILE_STOP_COLOR;
                ProfileStageLink link3 = pf.ListUrl.Where(l => l.Stage.Equals(3)).FirstOrDefault();
                if (pf.Verifier.ToString().Equals("") == false)
                {
                    ((Label)(e.Item.FindControl("lblPrefixNameVerifier"))).Text = PREFIX_NAME;
                }
                if (link3 != null)
                {
                    ((Label)e.Item.FindControl("lbVerifyTime")).Text = PREFIX_TIME + link3.EditTime;
                    ((Label)e.Item.FindControl("lblDescriptionVerifier")).Text = link3.Description.Length > MAX_DESCRIPTION ? link3.Description.Substring(0, MAX_DESCRIPTION) : link3.Description;
                    BindDetailForVerify(pf.ProfileCode, link3, e);
                }
            }
        }

        private void BindDataForStageApprover(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            ProfileStageLink link1 = pf.ListUrl.Where(l => l.Stage.Equals(1)).FirstOrDefault();
            if (link1 != null)
            {
                if (pf.Proposer.ToString().Equals("") == false)
                {
                    ((Label)(e.Item.FindControl("lblPrefixNameProposer"))).Text = PREFIX_NAME;
                }
                ((Label)e.Item.FindControl("lbProposeTime")).Text = PREFIX_TIME + link1.EditTime;
                BindDetailForPropose(pf.ProfileCode, link1, e);
            }
            ProfileStageLink link2 = pf.ListUrl.Where(l => l.Stage.Equals(2)).SingleOrDefault();
            if (pf.Filter.ToString().Equals("") == false)
            {
                ((Label)(e.Item.FindControl("lblPrefixNameFilter"))).Text = PREFIX_NAME;
            }
            if (link2 != null)
            {
                ((Label)e.Item.FindControl("lbFilterTime")).Text = PREFIX_TIME + link2.EditTime;
                BindDetailForFilter(pf.ProfileCode, link2, e);
            }
            ProfileStageLink link3 = pf.ListUrl.Where(l => l.Stage.Equals(3)).SingleOrDefault();
            if (pf.Verifier.ToString().Equals("") == false)
            {
                ((Label)(e.Item.FindControl("lblPrefixNameVerifier"))).Text = PREFIX_NAME;
            }
            if (link3 != null)
            {
                ((Label)e.Item.FindControl("lbVerifyTime")).Text = PREFIX_TIME + link3.EditTime;
                BindDetailForVerify(pf.ProfileCode, link3, e);
            }
            //((HtmlControl)e.Item.FindControl("sApprove")).Style["color"] = "White";
            if (pf.Status == 2)
            {
                ((HtmlControl)e.Item.FindControl("frameContentApprover")).Style["background-color"] = PROFILE_STOP_COLOR;
            }

            //else
            //{
            //    
            if (!string.IsNullOrEmpty(pf.Approver.ToString()))
            {
                ((Label)(e.Item.FindControl("lblPrefixNameApprover"))).Text = PREFIX_NAME;
            }
            ProfileStageLink link4 = pf.ListUrl.Where(l => l.Stage.Equals(4)).SingleOrDefault();
            if (link4 != null)
            {

                ((Label)e.Item.FindControl("lbApproveTime")).Text = PREFIX_TIME + link4.EditTime;
                BindDetailForApprove(pf.ProfileCode, link4, e);
            }
            //}
        }

        private void BindDataForStagePayment(ProfileInfoStatusDetail pf, RepeaterItemEventArgs e)
        {
            ProfileStageLink link1 = pf.ListUrl.Where(l => l.Stage.Equals(1)).SingleOrDefault();
            if (link1 != null)
            {
                if (pf.Proposer.ToString().Equals("") == false)
                {
                    ((Label)(e.Item.FindControl("lblPrefixNameProposer"))).Text = PREFIX_NAME;
                }
                ((Label)e.Item.FindControl("lbProposeTime")).Text = PREFIX_TIME + link1.EditTime;
                BindDetailForPropose(pf.ProfileCode, link1, e);
            }
            ProfileStageLink link2 = pf.ListUrl.Where(l => l.Stage.Equals(2)).SingleOrDefault();
            if (pf.Filter.ToString().Equals("") == false)
            {
                ((Label)(e.Item.FindControl("lblPrefixNameFilter"))).Text = PREFIX_NAME;
            }
            if (link2 != null)
            {
                ((Label)e.Item.FindControl("lbFilterTime")).Text = PREFIX_TIME + link2.EditTime;
                BindDetailForFilter(pf.ProfileCode, link2, e);
            }
            ProfileStageLink link3 = pf.ListUrl.Where(l => l.Stage.Equals(3)).SingleOrDefault();
            if (pf.Verifier.ToString().Equals("") == false)
            {
                ((Label)(e.Item.FindControl("lblPrefixNameVerifier"))).Text = PREFIX_NAME;
            }
            if (link3 != null)
            {
                ((Label)e.Item.FindControl("lbVerifyTime")).Text = PREFIX_TIME + link3.EditTime;
                BindDetailForVerify(pf.ProfileCode, link3, e);
            }
            ProfileStageLink link4 = pf.ListUrl.Where(l => l.Stage.Equals(4)).SingleOrDefault();
            if (link4 != null)
            {
                ((Label)e.Item.FindControl("lbApproveTime")).Text = PREFIX_TIME + link4.EditTime;
                BindDetailForApprove(pf.ProfileCode, link4, e);
            }
            //((HtmlControl)e.Item.FindControl("sPayment")).Style["color"] = "White";
            if (pf.Status == 2)
            {
                ((HtmlControl)e.Item.FindControl("frameContentPayment")).Style["background-color"] = PROFILE_STOP_COLOR;
            }
            ProfileStageLink link5 = pf.ListUrl.Where(l => l.Stage.Equals(5)).SingleOrDefault();
            if (link5 != null)
            {
                ((Label)e.Item.FindControl("lbPaymentTime")).Text = PREFIX_TIME + link5.EditTime;
                BindDetailForPayment(pf.ProfileCode, link5, e);
            }
        }*/

        private void BindDataForProfileDetail(string profileCode, PatientInfo patientInfo, MedicalInfo medicalInfo, RepeaterItemEventArgs e)
        {
            HyperLink linkProposeDesc = (HyperLink)e.Item.FindControl("showProfileDetail");
            linkProposeDesc.Visible = true;
            linkProposeDesc.Style["display"] = "block";
            //
            //
            //
            string profileDetail = string.Empty;
            string gender = string.Empty;
            if (patientInfo.Gender.Equals("Female"))
            {
                gender = "Nữ";
            }
            else
            {
                gender = "Nam";
            }
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Tên bệnh nhân:</span> " + patientInfo.PatientName + "<br />";
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Giới tính:</span> " + gender + "<br />";
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Ngày sinh:</span> " + patientInfo.Birthday.ToString("G", CultureInfo.CreateSpecificCulture("vi-VI")).Substring(0, 10) + "<br />";
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Địa chỉ:</span> " + patientInfo.PermanentAddress + "<br />";
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Địa chỉ điều trị:</span> " + patientInfo.MedicalFacility + "<br />";
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Bệnh án:</span> " + medicalInfo.Diagnosis + "<br />";
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Hoàn cảnh khó khăn:</span> " + medicalInfo.Situation + "<br />";
            profileDetail += "<span style='text-transform: none; text-decoration: underline;'>Cần giúp đỡ:</span> " + medicalInfo.Support + "<br />";
            //
            //
            //
            linkProposeDesc.Attributes.Add("onclick", "showProfileDetail('" + profileCode + "', \"" + profileDetail + "\");");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        /// <param name="controlName"></param>
        /// <param name="link"></param>
        private void createThumbnail(RepeaterItemEventArgs e, string controlName, string link)
        {
            Image thumbnailPhoto = (Image)e.Item.FindControl(controlName);
            thumbnailPhoto.ImageUrl = link;
            thumbnailPhoto.Width = THUMBNAILSIZE;
            thumbnailPhoto.Height = THUMBNAILSIZE;
            thumbnailPhoto.Style["border"] = "2px solid white";
            thumbnailPhoto.Style["border-radius"] = "2px 2px 2px 2px";
        }

        private void BindDetailForPropose(string profileCode, ProfileStageLink link, RepeaterItemEventArgs e)
        {
            if (!string.IsNullOrEmpty(link.Description) && link.Description.Length > MAX_DESCRIPTION)
            {
                HyperLink linkProposeDesc = (HyperLink)e.Item.FindControl("vProposeDesc");
                linkProposeDesc.Visible = true;
                linkProposeDesc.Style["display"] = "block";
                linkProposeDesc.Attributes.Add("onclick", "showDesc('" + profileCode + "', '" + link.Description + "');");
            }
            if (!string.IsNullOrEmpty(link.PhotoLink))
            {
                HyperLink linkProposePhoto = (HyperLink)e.Item.FindControl("vProposePhoto");
                linkProposePhoto.Visible = true;
                linkProposePhoto.Style["display"] = "block";
                linkProposePhoto.Attributes.Add("onclick", "showPhoto('" + profileCode + "', '" + link.PhotoLink + "');");
                createThumbnail(e, "thumbnailPhotoProposer", link.PhotoLink);
            }
            if (!string.IsNullOrEmpty(link.AudioLink))
            {
                HyperLink linkProposeAudio = (HyperLink)e.Item.FindControl("vProposeAudio");
                linkProposeAudio.Visible = true;
                linkProposeAudio.Style["display"] = "block";
                linkProposeAudio.Attributes.Add("onclick", "showAudio('" + profileCode + "', '" + link.AudioLink + "');");
                createThumbnail(e, "thumbnailAudioProposer", "images/thumbnailAudio.png");
            }
            if (!string.IsNullOrEmpty(link.VideoLink))
            {
                HyperLink linkProposeVideo = (HyperLink)e.Item.FindControl("vProposeVideo");
                linkProposeVideo.Visible = true;
                linkProposeVideo.Style["display"] = "block";
                linkProposeVideo.Attributes.Add("onclick", "showVideo('" + profileCode + "', '" + link.VideoLink + "');");
                createThumbnail(e, "thumbnailVideoProposer", "images/thumbnailVideo.png");
            }
        }

        private void BindDetailForFilter(string profileCode, ProfileStageLink link, RepeaterItemEventArgs e)
        {
            if (!string.IsNullOrEmpty(link.Description) && link.Description.Length > MAX_DESCRIPTION)
            {
                //((Label)e.Item.FindControl("lblDesFilter")).Visible = true;
                HyperLink linkFilterDesc = (HyperLink)e.Item.FindControl("vFilterDesc");
                linkFilterDesc.Visible = true;
                linkFilterDesc.Style["display"] = "block";
                linkFilterDesc.Attributes.Add("onclick", "showDesc('" + profileCode + "', '" + link.Description + "');");
            }
            if (!string.IsNullOrEmpty(link.PhotoLink))
            {
                HyperLink linkFilterPhoto = (HyperLink)e.Item.FindControl("vFilterPhoto");
                linkFilterPhoto.Visible = true;
                linkFilterPhoto.Style["display"] = "block";
                linkFilterPhoto.Attributes.Add("onclick", "showPhoto('" + profileCode + "', '" + link.PhotoLink + "');");
                createThumbnail(e, "thumbnailPhotoFilter", link.PhotoLink);
            }
            if (!string.IsNullOrEmpty(link.AudioLink))
            {
                HyperLink linkFilterAudio = (HyperLink)e.Item.FindControl("vFilterAudio");
                linkFilterAudio.Visible = true;
                linkFilterAudio.Style["display"] = "block";
                linkFilterAudio.Attributes.Add("onclick", "showAudio('" + profileCode + "', '" + link.AudioLink + "');");
                createThumbnail(e, "thumbnailAudioFilter", "images/thumbnailAudio.png");
            }
            if (!string.IsNullOrEmpty(link.VideoLink))
            {
                HyperLink linkFilterVideo = (HyperLink)e.Item.FindControl("vFilterVideo");
                linkFilterVideo.Visible = true;
                linkFilterVideo.Style["display"] = "block";
                linkFilterVideo.Attributes.Add("onclick", "showVideo('" + profileCode + "', '" + link.VideoLink + "');");
                createThumbnail(e, "thumbnailVideoFilter", "images/thumbnailVideo.png");
            }
        }

        private void BindDetailForVerify(string profileCode, ProfileStageLink link, RepeaterItemEventArgs e)
        {
            if (!string.IsNullOrEmpty(link.Description) && link.Description.Length > MAX_DESCRIPTION)
            {
                //((Label)e.Item.FindControl("lblVerifier")).Visible = true;
                HyperLink linkVerifyDesc = (HyperLink)e.Item.FindControl("vVerifyDesc");
                linkVerifyDesc.Visible = true;
                linkVerifyDesc.Style["display"] = "block";
                linkVerifyDesc.Attributes.Add("onclick", "showDesc('" + profileCode + "', '" + link.Description + "');");
            }
            if (!string.IsNullOrEmpty(link.PhotoLink))
            {
                HyperLink linkVerifyPhoto = (HyperLink)e.Item.FindControl("vVerifyPhoto");
                linkVerifyPhoto.Visible = true;
                linkVerifyPhoto.Style["display"] = "block";
                linkVerifyPhoto.Attributes.Add("onclick", "showPhoto('" + profileCode + "', '" + link.PhotoLink + "');");
                createThumbnail(e, "thumbnailPhotoVerifier", link.PhotoLink);
            }
            if (!string.IsNullOrEmpty(link.AudioLink))
            {
                HyperLink linkVerifyAudio = (HyperLink)e.Item.FindControl("vVerifyAudio");
                linkVerifyAudio.Visible = true;
                linkVerifyAudio.Style["display"] = "block";
                linkVerifyAudio.Attributes.Add("onclick", "showAudio('" + profileCode + "', '" + link.AudioLink + "');");
                createThumbnail(e, "thumbnailAudioVerifier", "images/thumbnailAudio.png");
            }
            if (!string.IsNullOrEmpty(link.VideoLink))
            {
                HyperLink linkVerifyVideo = (HyperLink)e.Item.FindControl("vVerifyVideo");
                linkVerifyVideo.Visible = true;
                linkVerifyVideo.Style["display"] = "block";
                linkVerifyVideo.Attributes.Add("onclick", "showVideo('" + profileCode + "', '" + link.VideoLink + "');");
                createThumbnail(e, "thumbnailVideoVerifier", "images/thumbnailVideo.png");
            }
        }

        private void BindDetailForApprove(string profileCode, ProfileStageLink link, RepeaterItemEventArgs e)
        {
            if (!string.IsNullOrEmpty(link.Description) && link.Description.Length > MAX_DESCRIPTION)
            {
                ((Label)e.Item.FindControl("lblDescriptionApprover")).Visible = true;
                HyperLink linkApproveDesc = (HyperLink)e.Item.FindControl("vApproveDesc");
                linkApproveDesc.Visible = true;
                linkApproveDesc.Style["display"] = "block";
                linkApproveDesc.Attributes.Add("onclick", "showDesc('" + profileCode + "', '" + link.Description + "');");
            }
            if (!string.IsNullOrEmpty(link.PhotoLink))
            {
                HyperLink linkApprovePhoto = (HyperLink)e.Item.FindControl("vApprovePhoto");
                linkApprovePhoto.Visible = true;
                linkApprovePhoto.Style["display"] = "block";
                linkApprovePhoto.Attributes.Add("onclick", "showPhoto('" + profileCode + "', '" + link.PhotoLink + "');");
                createThumbnail(e, "thumbnailPhotoApprover", link.PhotoLink);
            }
            if (!string.IsNullOrEmpty(link.AudioLink))
            {
                HyperLink linkApproveAudio = (HyperLink)e.Item.FindControl("vApproveAudio");
                linkApproveAudio.Visible = true;
                linkApproveAudio.Style["display"] = "block";
                linkApproveAudio.Attributes.Add("onclick", "showAudio('" + profileCode + "', '" + link.AudioLink + "');");
                createThumbnail(e, "thumbnailAudioApprover", "images/thumbnailAudio.png");
            }
            if (!string.IsNullOrEmpty(link.VideoLink))
            {
                HyperLink linkApproveVideo = (HyperLink)e.Item.FindControl("vApproveVideo");
                linkApproveVideo.Visible = true;
                linkApproveVideo.Style["display"] = "block";
                linkApproveVideo.Attributes.Add("onclick", "showVideo('" + profileCode + "', '" + link.VideoLink + "');");
                createThumbnail(e, "thumbnailVideoApprover", "images/thumbnailVideo.png");
            }
        }

        private void BindDetailForPayment(string profileCode, ProfileStageLink link, RepeaterItemEventArgs e)
        {
            if (!string.IsNullOrEmpty(link.Description) && link.Description.Length > MAX_DESCRIPTION)
            {
                ((Label)e.Item.FindControl("lblDescriptionPayment")).Style["display"] = "block";
                HyperLink linkPaymentDesc = (HyperLink)e.Item.FindControl("vPaymentDesc");
                linkPaymentDesc.Visible = true;
                linkPaymentDesc.Style["display"] = "block";
                linkPaymentDesc.Attributes.Add("onclick", "showDesc('" + profileCode + "', '" + link.Description + "');");
            }
            if (!string.IsNullOrEmpty(link.PhotoLink))
            {
                HyperLink linkPaymentPhoto = (HyperLink)e.Item.FindControl("vPaymentPhoto");
                linkPaymentPhoto.Visible = true;
                linkPaymentPhoto.Style["display"] = "block";
                linkPaymentPhoto.Attributes.Add("onclick", "showPhoto('" + profileCode + "', '" + link.PhotoLink + "');");
                createThumbnail(e, "thumbnailPhotoPayment", link.PhotoLink);
            }
            if (!string.IsNullOrEmpty(link.AudioLink))
            {
                HyperLink linkPaymentAudio = (HyperLink)e.Item.FindControl("vPaymentAudio");
                linkPaymentAudio.Visible = true;
                linkPaymentAudio.Style["display"] = "block";
                linkPaymentAudio.Attributes.Add("onclick", "showAudio('" + profileCode + "', '" + link.AudioLink + "');");
                createThumbnail(e, "thumbnailAudioPayment", "images/thumbnailAudio.png");
            }
            if (!string.IsNullOrEmpty(link.VideoLink))
            {
                HyperLink linkPaymentVideo = (HyperLink)e.Item.FindControl("vPaymentVideo");
                linkPaymentVideo.Visible = true;
                linkPaymentVideo.Style["display"] = "block";
                linkPaymentVideo.Attributes.Add("onclick", "showVideo('" + profileCode + "', '" + link.VideoLink + "');");
                createThumbnail(e, "thumbnailVideoPayment", "images/thumbnailVideo.png");
            }
        }
    }
}